<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">头像</td>
                    <td><input type="file" @change="Imgs">
                        <img :src="info.Img" width="100" height="100" v-if="info.Img != ''">
                    </td>
                </tr>
                <tr>
                    <td align="right">楼栋</td>
                    <td>
                        <select v-model="info.Xq">
                            <option value="">请选择</option>
                            <option :value="itme.Id" v-for="itme in lisr.a" :key="itme.Id">{{ itme.Guanli }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房间</td>
                    <td><input type="text" v-model="info.FJ"></td>
                </tr>
                <tr>
                    <td align="right">姓名</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td align="right">性别</td>
                    <td><input type="radio" name="sts" :value="true" v-model="info.Sex">男
                        <input type="radio" name="sts" :value="false" v-model="info.Sex">女
                    </td>
                </tr>
                <tr>
                    <td align="right">民族</td>
                    <td><input type="text" v-model="info.MZ"></td>
                </tr>
                <tr>
                    <td align="right">籍贯</td>
                    <td><input type="text" v-model="info.JG"></td>
                </tr>
                <tr>
                    <td align="right">证件</td>
                    <td><input type="text" v-model="info.SFZH"></td>
                </tr>
                <tr>
                    <td align="right">电话</td>
                    <td><input type="text" v-model="info.Tel"></td>
                </tr>
                <tr>
                    <td align="right">类型</td>
                    <td><select v-model="info.LX">
                            <option value="">请选择</option>
                            <option value="业主">业主</option>
                            <option value="租户">租户</option>
                        </select></td>
                </tr>
                <tr>
                    <td align="right">审核状态</td>
                    <td><input type="radio" name="st" :value="true" v-model="info.State">已审核
                        <input type="radio" name="st" :value="false" v-model="info.State">未审核
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const rouder = useRouter();
const roude = useRoute();
let info: any = reactive({
    "Id": roude.query.id,
    "Img": "",
    "Loudong": "",
    "FJ": "",
    "Name": "",
    "Sex": "",
    "MZ": "",
    "JG": "",
    "SFZH": "",
    "Tel": "",
    "LX": "",
    "Xq": "",
    "State": "",
})
let lisr: any = reactive({
    a: []
})
onMounted(() => {
    getlist();
    getFind();
})
const getlist = () => {
    axios({
        url: '/api/Wook/GetShow',
        method: 'get'
    })
        .then((res) => {
            console.log(res);
            lisr.a = res.data;
        })
        .catch((err) => {
            console.log(err);

        })

}

const Imgs = (e: any) => {
    let obj = e.target.files[0]
    let f = new FormData();
    f.append('file', obj)
    axios({
        url: '/api/Img/Imgs',
        method: 'post',
        data: f
    })
        .then((res) => {
            console.log(res);
            info.Img = res.data
        })
        .catch((err) => {
            console.log(err);
        })
}

const ok = () => {
    if (info.Name == "") {
        alert("姓名不能为空");
        return;
    }
    if (info.Xq == "") {
        alert("楼栋不能为空");
        return;
    }
    if (info.FJ == "") {
        alert("房间不能为空");
        return;
    }
    axios({
        url: '/api/Wook/Update',
        method: 'put',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert("姓名重复")
                return;
            }
            if (res.data > 0) {
                alert("修改成功");
                rouder.push('/showjm')
                return;
            }
            else {
                alert("修改失败");
                return;
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
//================反填
const getFind = () => {
    axios({
        url: '/api/Wook/Find',
        method: 'get',
        params: {
            id: roude.query.id
        }
    })
        .then((res) => {
            console.log(res);
            Object.assign(info, res.data)

        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>